package com.lk.common.result;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lk.common.constant.IConstant;

/**
 * 执行结果--统一的返回结果bean
 * @author lljun3
 * @version 1.0 2017年12月28日
 * @since 1.0
 * @param <T>
 */
@SuppressWarnings("unused")
public class BasicPageResp<T> {
	private String result = IConstant.OP_FAIL;							// 默认返回失败代码	
	private String msg = IConstant.OP_FAIL_MSG;							// 默认返回失败信息
	private int pageNo = 1; 											// 当前页,默认为1
	private int pageSize = 10; 											// 页面大小,默认为10
	private int first = 0; 												// limit 前面的那个值
	private int totalRow = 0; 											// 总行数
	private int totalPage = 0; 											// 总页面数
	private List<T> list; 												// 返回多个实体或者数据
	private T data;														// 返回单个实体或者数据
	private Map<String, Object> maps = new HashMap<String, Object>(); 	// 其他返回信息

	//空构造器
	public BasicPageResp() {
		
	}

	//分页时调用的构造器
	public BasicPageResp(int pageNo, int pageSize) {
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}

	public String getResult() {
		return result;
	}
	
	public void setResult(String result) {
		this.result = result;
	}

	public String getMsg() {
		return msg;
	}
	
	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getFirst() {
		return (this.pageNo - 1) * this.pageSize;
	}

	public void setFirst(int first) {
		this.first = first;
	}

	public int getTotalRow() {
		return totalRow;
	}

	public void setTotalRow(int totalRow) {
		this.totalRow = totalRow; 						// 设置总行数
		this.totalPage = (totalRow - 1) / pageSize + 1; // 设置总页数
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}
	
	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public Map<String, Object> getMaps() {
		return maps;
	}

	public void setMaps(Map<String, Object> maps) {
		this.maps = maps;
	}
	
	//传递params进行，设置first和last
	public void setFirstAndLast(Map<String,Object> params) {
		params.put("first", this.first);
		params.put("last", this.pageSize);
	}

}
